<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //1.设置猜1-10的随机数
    function getNumRandom(N, M) {
      return Math.floor(Math.random() * (M - N + 1)) + N
    }
    let random = getNumRandom(1, 10)
    let flag = true
    
    for (let i = 1; i <= 8; i++) {
      // 2.用户输入
      let num = +prompt('请输入1-10之间的数')
      if (num > random) {
        alert('猜大了')
      } else if (num < random) {
        alert('猜小了')
      } else {
        flag = false
        alert('猜对了,太厉害了')
        break
      }
    }
    if (flag) {
      alert('次数用完了')
    }
  </script>
</body>
</html>